/*
 * AppServNotificationnHandler.cpp
 *
 *  Created on: Apr 9, 2017
 *      Author: zhangjf
 */

#include "Packet.h"
#include "PacketReceiver.h"
#include "MainApplication.h"
#include "AppServNotificationnHandler.h"

using namespace util;

void AppServNotificationnHandler::run()
{
	PacketReceiver receiver(_streamSocket);

	try
	{
		while (true)
		{
			poco_information(*pLogger, "wait to receiving packet...");

			Packet* pack = receiver.recv();
			if (pack != nullptr)
			{
				poco_information(*pLogger, std::string("receive packet :") + pack->getData());
				_webSocket.sendBytes(pack->getData(), pack->getHeader()->length - 4);
			}
			Thread::sleep(100);
		}
	}
	catch (Exception& exc)
	{
		poco_information(*pLogger, "Exception: " + exc.displayText());
	}
}
